#include <iostream>
#include <cstdlib>

using namespace std;

struct Node
{
    int X;
    int Y;
    int groupID;
};

bool isNeighboor(int x,int y)
{
    if((x -y)>= -1 && (x-y)<=1 )
        return true;
    else
        return false;
}

void ergodic(char **Data, int **Weight,int N,int M,int _count,int i,int j)
{
    int currI,currJ;
    if(i == 0)
        currI = 0;
    else
        currI = i-1;
    if(j == 0)
        currJ = 0;
    else
        currJ = j-1;
    for(int m = currI; m<=i+1; m++)
    {
        for(int n =currJ;n<=j+1;n++)
    {
        if(Data[m][n] == 'W')
        {
            if(Weight[m][n] == 0)
            {
                Weight[m][n] = _count;
                ergodic(Data,Weight,N,M,_count,m,n);
            }
        }
    }
    }
}
int main()
{
    int N,M;
    cin>>N>>M;

    char **Data;
    int **Weight;
    Data = new char*[N+1];
    Weight = new int*[N+1];
    for(int i=0; i<N+1; i++)
    {
        Data[i] = new char[M+1];
        Weight[i] = new int[M+1];
    }
    for(int i=0; i<N+1; i++)
        for(int j=0; j<M+1; j++)
            Weight[i][j] = 0;

    for(int i=0; i<N; i++)
        for(int j=0; j<M; j++)
        cin>>Data[i][j];
    for(int j=0; j<M+1; j++)
        Data[N][j] = '.';
    for(int i=0; i<N+1; i++)
        Data[i][M] = '.';


    int _count = 0;
    int currentGroupId = 0;

    for(int i=0; i<N;i++)
    {
        for(int j=0; j<M;j++)
        {
            if(Data[i][j] == 'W')
            {
                if(Weight[i][j] == 0)
                {
                    _count++;
                    Weight[i][j] = _count;
                    ergodic(Data,Weight,N,M,_count,i,j);
                }
            }
        }
    }

    cout<<_count;
    for(int i=0; i<N+1; i++)
    {
        delete Data[i];
        delete Weight[i];
    }
    delete Data;
    delete Weight;

    return 0;
}
